package com.hongdee.market.bc.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.common.util.EntityUtils;
import com.hongdee.common.util.TokenUtil;
import com.hongdee.market.bc.entity.TBcCustomeItemScore;
import com.hongdee.market.bc.service.ITBcCustomItemSocreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dell on 2017/5/17.
 * 评分项目分值管理
 */
@RestController
@RequestMapping("/bc/custome/itemscore")
public class TBcCustomItemScoreController {
    @Autowired
    private ITBcCustomItemSocreService itBcCustomItemSocreService;

    /*
    * 查询分类列表
    * */
    @RequestMapping("/leftTree")
    @ResponseBody
    public ResultEntity tree(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token
    ) throws Exception {
        ResultEntity res = new ResultEntity();

        List dataList = this.itBcCustomItemSocreService.tree(uid);
        res.setDataList(dataList);
        res.setSuccess(true);
        res.setMsg("查询详情成功");
        return res;
    }

    /**
     * 停用
     */
    @RequestMapping("/stop")
    @ResponseBody
    public ResultEntity stop(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "id", defaultValue = "0") String id) throws Exception {
        ResultEntity res = new ResultEntity();
        itBcCustomItemSocreService.update(id, "0");
        res.setSuccess(true);
        res.setMsg("停用成功！");
        return res;
    }

    /**
     * 启用
     */
    @RequestMapping("/start")
    @ResponseBody
    public ResultEntity start(@RequestParam(name = "uid", defaultValue = "") String uid,
                              @RequestParam(name = "token", defaultValue = "") String token,
                              @RequestParam(name = "id", defaultValue = "0") String id) throws Exception {
        ResultEntity res = new ResultEntity();
        itBcCustomItemSocreService.update(id, "1");
        res.setSuccess(true);
        res.setMsg("启动成功！");
        return res;
    }

    /*
       * 查询
       * */
    @RequestMapping("/info")
    @ResponseBody
    public ResultEntity info(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "id", defaultValue = "") String id) throws Exception {
        ResultEntity res = new ResultEntity();
        Map map = itBcCustomItemSocreService.info(id);
        res.setData(map);
        res.setSuccess(true);
        res.setMsg("查询详情成功");
        return res;
    }



    /**
     * 新增、修改
     *
     * @param uid
     * @param token
     * @param tBcCustomeItemScore
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultEntity save(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestBody TBcCustomeItemScore tBcCustomeItemScore) throws Exception {
        EntityUtils.valid(tBcCustomeItemScore);
        tBcCustomeItemScore.setCompanyId(TokenUtil.getCompanyId(uid));
        TBcCustomeItemScore tc = itBcCustomItemSocreService.saveOrUpdate(tBcCustomeItemScore);
        ResultEntity res = new ResultEntity();
        res.setData(tc);
        res.setSuccess(true);
        res.setMsg("保存成功！");
        return res;
    }

    /*
  * 分页
  * */
    @RequestMapping("/list")
    @ResponseBody
    public Map newPage(@RequestParam(name = "uid", defaultValue = "") String uid,
                       @RequestParam(name = "token", defaultValue = "") String token,
                       @RequestParam(name = "start", defaultValue = "0") String start,
                       @RequestParam(name = "limit", defaultValue = "50") String limit,
                       @RequestParam(name = "id", defaultValue = "") String id
    ) throws Exception {
        String comId = TokenUtil.getCompanyId(uid);
        Map map = this.itBcCustomItemSocreService.newPage(comId, start, limit, id);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        System.out.print("1");
        return map;
    }

}
